home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Systemmonitors / LastGURU / LastGURU.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  16KB  |  447 lines

  1. /*
  2.  *    LastGURU
  3.  *    ¯¯¯¯¯¯¯¯
  4.  *        Based on Olaf Barthel's "LastAlert"
  5.  *
  6.  *        © 1996 by Timo C. Nentwig
  7.  *            All Rights Reserved
  8.  *
  9.  *        Tcn@techbase.in-berlin.de
  10.  *
  11.  *
  12.  *    Purpose
  13.  *    ¯¯¯¯¯¯¯
  14.  *        Simple program that opens a gtlayout window
  15.  *        and displays infomation about the last GURU
  16.  *
  17.  */
  18.  
  19.  
  20. #include    <exec/execbase.h>
  21. #include    <exec/alerts.h>
  22. #include    <proto/exec.h>
  23. #include    <libraries/gtlayout.h>
  24. #include    <stdio.h>
  25.  
  26. #define     PRG_TITLE      "LastGURU"
  27. #define     PRG_VERSION    "1.0"
  28. #define     PRG_AUTHOR     "Timo C. Nentwig"
  29. #define     PRG_EMAIL      "Tcn@techbase.in-berlin.de"
  30.  
  31.  
  32.        enum    { ID_GAD = 10, ID_MEN_QUIT = 20 };
  33.  
  34. GLOBAL struct    ExecBase   *SysBase;
  35. STATIC BYTE      __ver[]  =  "$VER: "PRG_TITLE" "PRG_VERSION" "__AMIGADATE__;
  36.  
  37.        STRPTR    GetDeclare    (ULONG ID, struct AlertInfo *List, BYTE ShowTraps);
  38.  
  39. struct    AlertInfo
  40. {
  41.  
  42.     ULONG     ID;
  43.     STRPTR    Text;
  44.  
  45. };
  46.  
  47. struct    AlertInfo    CauseList[] =
  48. {
  49.     AG_NoMemory,      "Not enough memory",
  50.     AG_MakeLib,       "Library initialization failed",
  51.     AG_OpenLib,       "Library failed to open",
  52.     AG_OpenDev,       "Device failed to open",
  53.     AG_OpenRes,       "Resource failed to open",
  54.     AG_IOError,       "I/O error",
  55.     AG_NoSignal,      "AllocSignal () failed",
  56.     AG_BadParm,       "Bad parameters",
  57.     AG_CloseLib,      "Invalid request to close library",
  58.     AG_CloseDev,      "Invalid request to close device",
  59.     AG_ProcCreate,    "Process creation failed",
  60.  
  61.     NULL,        NULL
  62. };
  63.  
  64. struct    AlertInfo    ObjectList[] =
  65. {
  66.     AO_ExecLib,         "exec.library",
  67.     AO_GraphicsLib,     "graphics.library",
  68.     AO_LayersLib,       "layers.library",
  69.     AO_Intuition,       "intuition.library",
  70.     AO_MathLib,         "math???.library",
  71.     AO_DOSLib,          "dos.library",
  72.     AO_RAMLib,          "ram.library",
  73.     AO_IconLib,         "icon.library",
  74.     AO_ExpansionLib,    "expansion.library",
  75.     AO_DiskfontLib,     "diskfont.library",
  76.     AO_UtilityLib,      "utility.library",
  77.     AO_AudioDev,        "audio.device",
  78.     AO_ConsoleDev,      "console.device",
  79.     AO_GamePortDev,     "gameport.device",
  80.     AO_KeyboardDev,     "keyboard.device",
  81.     AO_TrackDiskDev,    "trackdisk.device",
  82.     AO_TimerDev,        "timer.device",
  83.     AO_CIARsrc,         "cia.resource",
  84.     AO_DiskRsrc,        "disk.resource",
  85.     AO_MiscRsrc,        "misc.resource",
  86.     AO_BootStrap,       "BootStrap",
  87.     AO_Workbench,       "Workbench",
  88.     AO_DiskCopy,        "DiskCopy",
  89.     AO_GadTools,        "gadtools.library",
  90.     AO_Unknown,         "Unknown",
  91.  
  92.     NULL,               NULL
  93. };
  94.  
  95.  
  96. struct    AlertInfo    DescriptionList[] =
  97. {
  98.     AN_ExecLib,             "exec.library",
  99.     AN_ExcptVect,           "680x0 exception vector checksum corrupt",
  100.     AN_BaseChkSum,          "ExecBase checksum corrupt",
  101.     AN_LibChkSum,           "Library checksum corrupt",
  102.     AN_MemCorrupt,          "Corrupt memory list detected in FreeMem",
  103.     AN_IntrMem,             "No memory for interrupt servers",
  104.     AN_InitAPtr,            "InitStruct () of an APTR source",
  105.     AN_SemCorrupt,          "A semaphore is in an illegal state at ReleaseSempahore ()",
  106.     AN_FreeTwice,           "Freeing memory already freed",
  107.     AN_BogusExcpt,          "Illegal 680x0 exception taken",
  108.     AN_IOUsedTwice,         "Attempt to reuse active IORequest",
  109.     AN_MemoryInsane,        "Sanity check on memory list failed during AvailMem (MEMF_LARGEST)",
  110.     AN_IOAfterClose,        "I/O attempted on closed IORequest",
  111.     AN_StackProbe,          "Stack appears to extend out of range",
  112.     AN_BadFreeAddr,         "Memory header not located,  usually an invalid address passed to FreeMem ()",
  113.     AN_GraphicsLib,         "graphics.library",
  114.     AN_GfxNoMem,            "graphics.library out of memory",
  115.     AN_GfxNoMemMspc,        "Not enough memory for MonitorSpec",
  116.     AN_LongFrame,           "Not enough memory for long frame copper list",
  117.     AN_ShortFrame,          "Not enough memory for short frame copper list",
  118.     AN_TextTmpRas,          "Not enough memory for text rendering",
  119.     AN_BltBitMap,           "Not enough memory for BltBitMap ()",
  120.     AN_RegionMemory,        "Not enough memory for clip regions",
  121.     AN_MakeVPort,           "Not enough memory for MakeVPort ()",
  122.     AN_GfxNewError,         "Memory allocation error",
  123.     AN_GfxFreeError,        "Memory deallocation error",
  124.     AN_GfxNoLCM,            "Emergency memory not available",
  125.     AN_ObsoleteFont,        "Unsupported font description used",
  126.     AN_LayersLib,           "layers.library",
  127.     AN_LayersNoMem,         "layers.library ran out of memory",
  128.     AN_Intuition,           "intuition.library",
  129.     AN_GadgetType,          "Unknown gadget type",
  130.     AN_BadGadget,           "Unknown gadget type",
  131.     AN_CreatePort,          "MsgPort creation failed",
  132.     AN_ItemAlloc,           "MenuItem plane allocation failed",
  133.     AN_SubAlloc,            "MenuSubItem allocation failed",
  134.     AN_PlaneAlloc,          "Plane allocation failed",
  135.     AN_ItemBoxTop,          "Item box top < RelZero",
  136.     AN_OpenScreen,          "Not enough memory to open screen",
  137.     AN_OpenScrnRast,        "Not enough memory to open screen",
  138.     AN_SysScrnType,         "Unknown system screen type",
  139.     AN_AddSWGadget,         "Not enough memory to add gadgets",
  140.     AN_OpenWindow,          "Not enough memory to open window",
  141.     AN_BadState,            "Bad State Return entering Intuition ()",
  142.     AN_BadMessage,          "Bad Message received by IDCMP",
  143.     AN_WeirdEcho,           "Weird echo causing incomprehension",
  144.     AN_NoConsole,           "Couldn't open the Console Device",
  145.     AN_MathLib,             "math???.library",
  146.     AN_DOSLib,              "dos.library",
  147.     AN_StartMem,            "Not enough memory at startup",
  148.     AN_EndTask,             "EndTask () didn't terminate process",
  149.     AN_QPktFail,            "QueuePacket () failed",
  150.     AN_AsyncPkt,            "Unexpected packet received",
  151.     AN_FreeVec,             "FreeVec () failed",
  152.     AN_DiskBlkSeq,          "Disk block sequence error",
  153.     AN_BitMap,              "Bitmap corrupt",
  154.     AN_KeyFree,             "Key already free",
  155.     AN_BadChkSum,           "Invalid checksum",
  156.     AN_DiskError,           "Disk Error",
  157.     AN_KeyRange,            "Key out of range",
  158.     AN_BadOverlay,          "Bad overlay",
  159.     AN_BadInitFunc,         "Invalid initialization packet for CLI/Shell",
  160.     AN_FileReclosed,        "A filehandle was closed more than once",
  161.     AN_RAMLib,              "ram.library",
  162.     AN_BadSegList,          "Overlay detected in library seglist",
  163.     AN_IconLib,             "icon.library",
  164.     AN_ExpansionLib,        "expansion.library",
  165.     AN_BadExpansionFree,    "Freed free region",
  166.     AN_DiskfontLib,         "diskfont.library",
  167.     AN_AudioDev,            "audio.device",
  168.     AN_ConsoleDev,          "console.device",
  169.     AN_NoWindow,            "Console can't open window",
  170.     AN_GamePortDev,         "gameport.device",
  171.     AN_KeyboardDev,         "keyboard.device",
  172.     AN_TrackDiskDev,        "trackdisk.device",
  173.     AN_TDCalibSeek,         "Seek error during calibration",
  174.     AN_TDDelay,             "Error on timer wait",
  175.     AN_TimerDev,            "timer.device",
  176.     AN_TMBadReq,            "Bad timerequest",
  177.     AN_TMBadSupply,         "Bad power supply",
  178.     AN_CIARsrc,             "cia.resource",
  179.     AN_DiskRsrc,            "disk.resource",
  180.     AN_DRHasDisk,           "GetUnit () already has disk",
  181.     AN_DRIntNoAct,          "No active unit for interrupt",
  182.     AN_MiscRsrc,            "misc.resource",
  183.     AN_BootStrap,           "bootstrap",
  184.     AN_BootError,           "Boot code returned an error",
  185.     AN_Workbench,           "Workbench",
  186.     AN_DiskCopy,            "DiskCopy",
  187.     AN_GadTools,            "gadtools.library",
  188.     AN_UtilityLib,          "utility.library",
  189.     AN_Unknown,             "Unknown",
  190.  
  191.     0x00000002,             "Bus error",
  192.     0x00000003,             "Bad aligned address",
  193.     0x00000005,             "Division by zero",
  194.     0x00000006,             "Check instruction",
  195.     0x00000007,             "Trap instruction",
  196.     0x00000008,             "Privilege violation",
  197.     0x00000009,             "Trace mode",
  198.     0x0000000A,             "LineA emulation",
  199.     0x0000000B,             "Bus error",
  200.     0x0000000D,             "Coprocessor protocol violation",
  201.     0x0000000E,             "Format error",
  202.  
  203.     0x80000002,             "Bus error",
  204.     0x80000003,             "Bad aligned address",
  205.     0x80000005,             "Division by zero",
  206.     0x80000006,             "Check instruction",
  207.     0x80000007,             "Trap instruction",
  208.     0x80000008,             "Privilege violation",
  209.     0x80000009,             "Trace mode",
  210.     0x8000000A,             "LineA emulation",
  211.     0x8000000B,             "Bus error",
  212.     0x8000000D,             "Coprocessor protocol violation",
  213.     0x8000000E,             "Format error",
  214.  
  215.     NULL,                   NULL,
  216.  
  217. };
  218.  
  219.  
  220. /// main ()
  221.  
  222. VOID
  223. main (UWORD argc, STRPTR argv[])
  224. {
  225.  
  226.         // at least OS2 is required
  227.     if (!SysBase || SysBase -> LibNode.lib_Version < 37)
  228.     {
  229.  
  230.         printf (PRG_TITLE" requires at least AmigaOS v37\n");
  231.  
  232.     }
  233.     else
  234.     {
  235.  
  236.         if (*argv[1] == '?')
  237.         {
  238.  
  239.             printf ("");
  240.             printf (PRG_TITLE" "PRG_VERSION" ("__AMIGADATE__")\n");
  241.             printf ("© 1996 by "PRG_AUTHOR"\n");
  242.             printf ("");
  243.             printf ("all rights reserved\n");
  244.             printf ("\n");
  245.             printf (PRG_EMAIL"\n");
  246.  
  247.         }
  248.         else
  249.         {
  250.  
  251.             struct    GTLayoutBase   *GTLayoutBase;
  252.  
  253.  
  254.             if (NULL != (GTLayoutBase = (struct GTLayoutBase *) OpenLibrary ("gtlayout.library", 0)))
  255.             {
  256.  
  257.                 struct    LayoutHandle   *handle;
  258.  
  259.                 ULONG    *GuruData = (ULONG *) 0x0100;
  260.                 ULONG     Guru;
  261.                 ULONG     Task;
  262.  
  263.                 STRPTR    lab_list[7];
  264.                 STRPTR    gad_list[7];
  265.  
  266.                 if (! (Guru = GuruData[0]))
  267.                 {
  268.  
  269.                     Guru = SysBase -> LastAlert[0];
  270.                     Task = SysBase -> LastAlert[1];
  271.  
  272.                 }
  273.                 else
  274.                     Task = GuruData[1];
  275.  
  276.  
  277.                 {
  278.  
  279.                     UBYTE    tmp_guru[10];
  280.                     UBYTE    tmp_task[10];
  281.  
  282.                     sprintf (tmp_guru, "$%08X", Guru);
  283.                     sprintf (tmp_task, "$%08X", Task);
  284.  
  285.                     gad_list[0]  =  tmp_guru;
  286.                     gad_list[1]  =  tmp_task;
  287.                     gad_list[2]  =  (Guru & AT_DeadEnd) ? "Dead end alert" : "Recoverable alert";
  288.                     gad_list[3]  =  GetDeclare (Guru & 0x000F0000, CauseList,       FALSE);
  289.                     gad_list[4]  =  GetDeclare (Guru & 0x0000F00F, ObjectList,      FALSE);
  290.                     gad_list[5]  =  GetDeclare (Guru,              DescriptionList, FALSE);
  291.                     gad_list[6]  =  NULL;
  292.  
  293.                     lab_list[0]  =  "Number";
  294.                     lab_list[1]  =  "Task";
  295.                     lab_list[2]  =  "Type";
  296.                     lab_list[3]  =  "Cause";
  297.                     lab_list[4]  =  "Object";
  298.                     lab_list[5]  =  "Description";
  299.                     lab_list[6]  =  NULL;
  300.  
  301.                 }
  302.  
  303.  
  304.                 if (handle = LT_CreateHandleTags (NULL, TAG_END))
  305.                 {
  306.  
  307.                     struct    Window   *win;
  308.  
  309.  
  310.                     LT_New (handle, LA_Type,         VERTICAL_KIND,
  311.                                     LA_LabelText,    PRG_TITLE,
  312.                                     TAG_END);
  313.                                     {
  314.  
  315.                                         UWORD    i;
  316.  
  317.                                         for (i = 0; i < 6; i++)
  318.                                         {
  319.  
  320.                                             LT_New (handle, LA_Type,        TEXT_KIND,
  321.                                                             LA_ID,          ID_GAD + i,
  322.                                                             LA_HighLabel,   TRUE,
  323.                                                             LA_LabelText,   lab_list[i],
  324.                                                             GTTX_Text,      gad_list[i],
  325.                                                             GTTX_Border,    TRUE,
  326.                                                             TAG_END);
  327.  
  328.  
  329.                                             if (i == 1 || i == 2)
  330.                                             {
  331.  
  332.                                                 LT_New (handle, LA_Type,    XBAR_KIND,
  333.                                                                 TAG_END);
  334.  
  335.                                             }
  336.  
  337.                                         }
  338.  
  339.                                         LT_EndGroup (handle);
  340.  
  341.                                     }
  342.  
  343.  
  344.                     if (win = LT_Build (handle, LAWN_Title,          PRG_TITLE" "PRG_VERSION,
  345.                                                 LAWN_IDCMP,          IDCMP_CLOSEWINDOW,
  346.                                                 LAWN_AutoRefresh,    TRUE,
  347.                                                 LAWN_Zoom,           TRUE,
  348.                                                 WA_CloseGadget,      TRUE,
  349.                                                 WA_DepthGadget,      TRUE,
  350.                                                 WA_DragBar,          TRUE,
  351.                                                 WA_RMBTrap,          TRUE,
  352.                                                 TAG_END))
  353.                                                 {
  354.  
  355.                                                              struct    IntuiMessage   *Msg;
  356.                                                              BOOL                      done = FALSE;
  357.                                                     REGISTER ULONG                     MsgClass;
  358.                                                     REGISTER UWORD                     MsgCode;
  359.  
  360.                                                     while (done == FALSE)
  361.                                                     {
  362.  
  363.                                                         while (Msg = LT_GetIMsg (handle))
  364.                                                         {
  365.  
  366.                                                             MsgClass      =  Msg -> Class;
  367.                                                             MsgCode       =  Msg -> Code;
  368.                                                             LT_ReplyIMsg    (Msg);
  369.  
  370.                                                             switch (MsgClass)
  371.                                                             {
  372.  
  373.                                                                 case IDCMP_CLOSEWINDOW:
  374.  
  375.                                                                     done = TRUE;
  376.                                                                     break;
  377.  
  378.                                                             }
  379.  
  380.                                                         }
  381.  
  382.                                                     }
  383.  
  384.                                                 }
  385.  
  386.                     LT_DeleteHandle (handle);
  387.  
  388.                 }
  389.  
  390.                 CloseLibrary ((struct Library *) GTLayoutBase);
  391.  
  392.             }
  393.  
  394.         }
  395.  
  396.     }
  397.  
  398. }
  399.  
  400. ///
  401. /// GetDeclare ()
  402.  
  403.     /*
  404.      *    FUNCTION    Picks the text for given ID
  405.      *
  406.      *    NOTE
  407.      *
  408.      *    EXAMPLE     GetDeclare (Guru & 0x000F0000, CauseList, FALSE);
  409.      *
  410.      */
  411.  
  412.  
  413. STRPTR
  414. GetDeclare (ULONG ID, struct AlertInfo *List, BYTE ShowTraps)
  415. {
  416.  
  417.     LONG i;
  418.  
  419.     for (i = 0; List[i].Text; i++)
  420.     {
  421.  
  422.         if (ID == List[i].ID)
  423.             return (List[i].Text);
  424.  
  425.     }
  426.  
  427.     if (ShowTraps)
  428.     {
  429.  
  430.         STATIC UBYTE Buffer[20];
  431.  
  432.         if ( (ID & ~0x80000000))
  433.         {
  434.  
  435.             sprintf (Buffer, "Trap #%d", ID & ~0x80000000);
  436.             return (Buffer);
  437.  
  438.         }
  439.  
  440.     }
  441.  
  442.     return ("Not specified");
  443.  
  444. }
  445.  
  446. ///
  447.